package xxy.com.customview.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import xxy.com.customview.R;
import xxy.com.customview.view.MyButton;

/**
 * Created by Administrator on 2017/12/6.
 */

public class Main5Adapter extends RecyclerView.Adapter<Main5Adapter.Main5Holder> {

    private  Context mContext;
    private MyButton.MyClick myClick;

    public Main5Adapter(Context context) {
        this.mContext = context;
    }

    @Override
    public Main5Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.main5_recyclerview, parent, false);
        return new Main5Holder(view);
    }

    @Override
    public void onBindViewHolder(Main5Holder holder, final int position) {
        if (position % 2 == 0) {
            holder.imageView.setImageResource(R.drawable.rouhezhimei);
            holder.textView.setText("总是有人给我制造很多压力，但我不给自己制造压力。我觉得只要我开始打比赛后，它们就会自生自灭.");
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 20;
    }

    public class Main5Holder extends RecyclerView.ViewHolder {
        private View mView;
        private ImageView imageView;
        private TextView textView;

        public Main5Holder(View itemView) {
            super(itemView);
            this.mView = itemView;
            initView();
        }

        private void initView() {
            imageView = (ImageView) mView.findViewById(R.id.rl_iv);
            textView = (TextView) mView.findViewById(R.id.rl_tv_content);
        }
    }

    public interface MyClick {
        public void mClick();
    }

    public void setOnClickListener(MyButton.MyClick myClick) {
        this.myClick = myClick;
    }
}
